#include <iostream>
using namespace std;

class Test
{
public:
    void merge(int *nums1, int nums1Size, int m, int *nums2, int nums2Size, int n)
    {
        int i = m - 1;
        int j = n - 1;
        int dst = m + n - 1;
        while (i >= 0 && j >= 0)
        {
            if (nums1[i] > nums2[j])
            {
                //等价于分开写dst--, j--
                nums1[dst--] = nums1[i--];
            }
            else
            {
                nums1[dst--] = nums2[j--];
            }
        }

        while (j >= 0)
        {
            nums1[dst--] = nums2[j--];
        }
    }
};

int main()
{
    int Array1[6] = {128, 498, 575, 0, 0, 0};
    int Array2[3] = {268, 326, 425};

    Test t1;
    t1.merge(Array1, 6, 3, Array2, 3, 3);
    for (int i = 0; i < 6; ++i)
    {
        cout << Array1[i] << ' ';
    }
    cout << endl;
    system("pause");
    return 0;
}